import 'dart:ffi' as ffi;

import 'package:test/test.dart';
import 'package:ffi/ffi.dart' as ffi_pkg;

// NOTE: 单测环境下不强制依赖 ffigen 生成的 N-API 绑定。

void main() {
  group('napi string roundtrip (ffi only, env placeholder)', () {
    // Note: This test uses a null env placeholder because actual napi_env
    // must be provided by ETS/JSVM at runtime. Here we only validate
    // binding presence and call shapes, without real invocation.

    test('ffi is available (no binding requirement)', () {
      // 仅验证 dart:ffi 可用，避免强依赖生成绑定。
      expect(() => ffi.DynamicLibrary.process(), returnsNormally);
    });

    test('prepare buffers (UTF-16) without real call', () {
      final input = 'Hello Napi';
      final units = input.codeUnits;
      // Just ensure we can prepare native buffers; real calls require env.
      final buf = ffi_pkg.calloc<ffi.Uint16>(units.length);
      for (var i = 0; i < units.length; i++) {
        buf[i] = units[i];
      }
      ffi_pkg.calloc.free(buf);
      expect(true, isTrue);
    });
  });
}



